﻿#include "stdafx.h"
#include "configure.h"

CConfigure::CConfigure()
{
    m_nNoPersonTime = 10;
    char content[256];
    memset(content, 0, 256);
    if (GetProfileString("BASE", "NoPersonTime",content,256,"param.ini"))
    {
        m_nNoPersonTime = atoi(content);
#ifdef DEBUG
        m_nNoPersonTime = 10;
#endif
        printf("NoPersonTime=%d\n", m_nNoPersonTime);

    }
}

CConfigure::~CConfigure()
{

}

int CConfigure::GetNoPersonTime()
{
    return m_nNoPersonTime;
}

void CConfigure::SetNoPersonTime(char *buf)
{
    long time = ntohl(*(long *)(buf+4));
    printf("SetNoPersonTime=%ld\n", time);
    char content[256];
    memset(content, 0, 256);

    sprintf(content, "%ld", time);

    if (PutProfileString("BASE", "NoPersonTime",content,"param.ini"))
    {
        m_nNoPersonTime = time;
    }
}

//负责时间的解包
void CConfigure::SyncSystemTime(char *buf)
{
    long time = ntohl(*(long *)(buf+4));
    printf("sync time = %ld\n", time);
    SyncSystemTime(time);
    system("reboot");    
}

//校验时间
void CConfigure::SyncSystemTime(long time)
{
    //int ret = stime((time_t*)&time);
    int ret = 0;
    if(ret < 0)
    {
        printf("set local time error");
        return;
    }
    else if(ret == 0)printf("set local time ok");
    //system("rtc -s hw");
}

